/*
 * @Descripttion: 
 * @Author: voanit
 * @Date: 2022-09-06 09:03:52
 * @LastEditors: voanit
 * @LastEditTime: 2022-09-11 16:51:22
 */
import { defineStore } from "pinia"
import request from '@/utils/request'
import { ApiRes, BannerItem, NewItem, HotItem, BrandItem, Special } from '@/types/data'



const useHomeStore = defineStore('home', {
  state: () => {
    return {
      // list: [] as CategoryItem[],//类型断言
      bannerList: [] as BannerItem[],
      newGoodList: [] as NewItem[],
      hotGoodList: [] as HotItem[],
      // 品牌数据
      brandList: [] as BrandItem[],
      specialList: [] as Special[],
    }
  },
  actions: {
    async getBannerList() {
      const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
      this.bannerList = res.data.result
    },
    async getNewList() {
      const res = await request.get<ApiRes<NewItem[]>>('/home/new')
      this.newGoodList = res.data.result
    },
    async getHotList() {
      const res = await request.get<ApiRes<HotItem[]>>('/home/hot')
      this.hotGoodList = res.data.result
    },
    async getBrandList() {
      const res = await request.get<ApiRes<BrandItem[]>>('/home/brand')
      console.log(res)
      this.brandList = res.data.result
    },
    async getSpecialList() {
      const res = await request.get<ApiRes<Special[]>>('/home/special')
      this.specialList = res.data.result
    },
  },
  getters: {}
})

export default useHomeStore